package com.itheima.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @program: Spring_day02_01_注解_IoC注解
 * @description:
 * @author: zhanghz001
 * @create: 2020-11-28 03:50
 **/
public class MybatisConfig {
    // @Bean
    //Spring mybatis 后控制的创建连接用的对象
    public SqlSessionFactoryBean sqlSessionFactoryBean(
            @Autowired DruidDataSource druidDataSource) {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(druidDataSource);
        bean.setTypeAliasesPackage("com.itheima.domain");
        return bean;
    }

    //
    // @Bean
    //加载mybatis的映射配置扫描,作为spring的bean作为管理
    // 生成文件夹的bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer configurer = new MapperScannerConfigurer();
        configurer.setBasePackage("com.itheima.dao");
        return configurer;
    }
}
